var Select = {
    myScroll:null,
    pullDown:$("#pullDown"),  
    pullUp:$("#pullUp"),  
    pullDownLabel:$(".pullDownLabel"),  
    pullUpLabel:$(".pullUpLabel"),  
    loadingStep:0,//加载状态0默认，1显示加载状态，2执行加载数据 
    getData:function(type){
        var _this = this; 
        $.ajax({
            url: 'http://chinafengren.com/ajx/mpArticles',
            timeout: 60000,
            data: {},
            success: function (r) {
                var datas = JSON.parse(r);
                _this.creatList(datas.data,type);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log("textStatus:" + textStatus + "--error:" + jqXHR.responseText);
            }
        })
    },
    creatList:function(data,type){
        var str = "";
        data.forEach(function(element) {
            str += template(element)
        });
        if(data.length<=0){this.pullUpLabel.text("没有数据啦！");return;}
        if(type == 1){
            $(".select_list").html(str);
            this.loaded();
        }else{
            $(".select_list").append(str);
            this.myScroll.refresh();  
            this.loadingStep = 0;  
        }
    },
    loaded:function(){
        var _this = this;
        this.myScroll = new IScroll("#wrapper", {  
            scrollY:true,  
            probeType: 2,  
            bindToWrapper:true  
        });
        this.myScroll.on("scroll",function(){  
            if(_this.loadingStep == 0 && !_this.pullDown.attr("class").match('refresh|loading') && !_this.pullUp.attr("class").match('refresh')){  
                if(this.y > 40){//下拉刷新操作  
                    $(".pulldown-tips").hide();  
                    _this.pullDown.addClass("refresh").show();  
                    _this.pullDownLabel.text("松手刷新数据");  
                    _this.loadingStep = 1;  
                    myScroll.refresh();  
                }else if(this.y < (this.maxScrollY - 60)){//上拉加载更多  
                    _this.pullUp.addClass("refresh").show();  
                    _this.pullUpLabel.text("正在载入");  
                    _this.loadingStep = 1;  
                    _this.pullUpAction();  
                }  
            }  
        }); 
        this.myScroll.on("scrollEnd",function(){  
            if(_this.loadingStep == 1){  
                if( _this.pullDown.attr("class").match("refresh") ){//下拉刷新操作  
                    _this.pullDown.removeClass("refresh").addClass("loading");  
                    _this.pullDownLabel.text("正在刷新");  
                    _this.loadingStep = 2;  
                    _this.pullDownAction();  
                }  
            }  
        }); 
    },
    pullDownAction:function(){
        var _this = this;
        setTimeout(function(){  
            _this.pullDown.attr('class','').hide();  
            _this.myScroll.refresh();  
            _this.loadingStep = 0;  
            $(".pulldown-tips").show();  
            window.location.reload();
        },1000);  
    },
    pullUpAction:function(){
        var _this = this; 
        setTimeout(function(){ 
            Select.getData(2)
            _this.pullUp.attr('class','').hide();  
        },1000); 
    }
}  